package com.qfmy.webapp.service.impl.common;

import com.qfmy.model.entity.common.Announcement;
import com.qfmy.model.vo.common.AnnouncementVo;
import com.qfmy.webapp.mapper.common.AnnouncementMapper;
import com.qfmy.webapp.service.common.AnnouncementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * @author 清风明月
 * @Package com.qfmy.web.app.service.impl.wallpaper
 * @date 2025/11/26
 * @description 公告服务
 */
@Service
@SuppressWarnings("all")
public class AnnouncementServiceImpl implements AnnouncementService {

    /**
     * 创建公告mapper
     */
    @Autowired
    private AnnouncementMapper announcementMapper;


    /**
     * 根据类型获取公告
     * @param type
     * @return
     */
    @Override
    public List<AnnouncementVo> getAnnouncementByType(Integer type) {
        //查询数据库
        List<Announcement> announcements = announcementMapper.getAnnouncementByType(type);
        if (announcements != null) {
            //将数据库查询结果转换为vo
            List<AnnouncementVo> announcementVos = announcements.stream().map(announcement -> new AnnouncementVo(announcement.getId(), announcement.getContent())).toList();
            return announcementVos;
        }
        return Collections.emptyList();
    }
}
